package com.rongma.waterdrop.global;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Toast;

import com.rongma.waterdrop.utils.ActivityCollector;
import com.rongma.waterdrop.utils.LogUtils;

/**
 * Created by RongMa on 16/5/28.
 */
public abstract class BaseActivity extends Activity
{
    private  Toast toast;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        LogUtils.show("当前Activity是:" + this.getClass().getSimpleName());
        ActivityCollector.addActivity(this);
        initViriables();  //初始化成员变量
        bindView(savedInstanceState); //绑定View布局控件
        getData(); //获取数据
    }

    protected abstract void initViriables();

    protected abstract void bindView(Bundle savedInstanceState);

    protected abstract void getData();

    @Override
    protected void onDestroy() {
        super.onDestroy();
        ActivityCollector.removeActivity(this);
    }

    protected void showToast(String msg)
    {
        if(toast != null)
        {
            toast.setText(msg);
        }
        else {
            toast = Toast.makeText(this, msg, Toast.LENGTH_SHORT);
        }
        toast.show();
    }

    protected void toOtherActivity(Class activityClass)
    {
        Intent intent = new Intent(this,activityClass);
        startActivity(intent);
    }
}
